class User < ActiveRecord::Base
  
  $Midnight = 0
  $Noon = 12
  $Evening = 19
  
  attr_accessor :password_confirmation
  
  validates_presence_of :name, :email, :password, :privilege, :message => "is required"
  validates_uniqueness_of :email => "must be unique; this mail has already been registered"
  validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i , :message => "has an invalid format"
  validates_length_of :password, :minimum => 6, :message => 'must have 6 characters at least' 
  validates_confirmation_of :password
  
    def greeting_display
        t = Time.now
        #This line is needed since when we create an integer it does not like the fact when is passed a number starting with 0.
        hour = unless(t.strftime("%H").to_i < 10) then t.strftime("%H").to_i else t.strftime("%H").split("0")[1].to_i end
        if(hour >= $Midnight && hour < $Noon) 
          return "Good Morning "+self.name
        elsif (hour >= $Noon && hour < $Evening)
          return "Good afternoon "+self.name
        else
          "Good evening " + self.name
        end
    end
  
end
